#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    int n, k;
    cin >> n >> k;
    
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    ll res = 0;
    ll mn=0x3f3f3f3f;
    
    for (int i = 0; i < n; i++) {
        res += abs(a[i] - b[i]);
    }
    
    vector<ll> ds;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ll original = abs(a[i] - b[i]) + abs(a[j] - b[j]);
            ll option1 = abs(a[j] - b[i]) + abs(a[i] - b[j]);
            ll option2 = abs(b[j] - b[i]) + abs(a[i] - a[j]);
            ll option3 = abs(a[i] - a[j]) + abs(b[j] - b[i]);
            ll option4 = abs(a[i] - b[j]) + abs(a[j] - b[i]);
            
            ll max_option = max({original, option1, option2, option3, option4});
            ll gain = max_option - original;
            ds.push_back((gain<0LL?0LL:gain));
        }
    }
    sort(ds.begin(),ds.end());
    int idx=0;
    while(k--){
        res+=ds[idx++];
    }
    cout << res << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}